<?php
/*
2016-11-22 吴俊源
品牌模块
*/
class BrandAction extends CommonAction {
	function index(){
        $pagesize = 30;
		//如果用户指定分页大小，则使用用户指定的数量进行分页
        if ($this->_get('pagesize')) {
            $pagesize = intval($this->_get('pagesize'));
        }
		
        $listmap = 's.site_id = '.__SITEID__;
		//实例化供货商表模型，以便进行数据读取
        $BranddB = D('Brand');
		//是否有搜索关键词提交上来
		if(isset($_GET['keywords'])){
			//用户可以通过店名搜索到记录
			$listmap .= " and title like '%".($_GET['keywords'])."%'";
		}
		//计算全部数据个数，以便进行分页
		$count = $BranddB->alias('s')->where($listmap)->count();
		//引入分类类
        import('ORG.Util.Page');
		//实例化分页类
        $p = new Page($count, $pagesize);
		//开始分页查询
        $list = $BranddB->alias('s') -> Field('s.*') ->where($listmap)->limit($p->firstRow . ',' . $p->listRows) -> order($order) -> select();
		//生成分页字符串
		$pages = $p->show();
		//填充数据列表
		$this->assign('list', $list);
		//填充分页字符
		$this->assign('pages', $pages);
		//显示页面
		$this->display();
	}
	
	
	
	//品牌下的产品
	public function product(){
		
	}
	
	
	//重写显示页面方法，迎合前端实现ajax数据传输
	public function display($temp = ''){
		$map  = "site_id = ".__SITEID__." and groupname = '".strtolower(GROUP_NAME)."' and (modelname = '".strtolower(MODULE_NAME)."' or modelname = '*') and (actionname = '".strtolower(ACTION_NAME)."' or actionname = '*')";
		$Systempages = M('Systempages') -> where($map) -> find();
		if(IS_AJAX){
			
			$html = '';
			if($Systempages){
				$ModulesDB = D('Modules');
				$this->initView();
				$this->getModulesByID($this->view, $ModulesDB);
				$html .= $this->view -> fetch(TMPL_PATH.'Home/TemplateDefault/Supplier-header.html');
				$html .= $ModulesDB->getListToString($Systempages['page_view_id'],$this->view,false,true);
				$html .= $this->view -> fetch(TMPL_PATH.'Home/TemplateDefault/Supplier-footer.html');
			}else{
				$html = $this->fetch($temp);
			}
			$list = $_GET['list'];
			$empty = 1;
			$statu=$list?1:0; 
			if($this->get('list')){
				$empty = 0;
			}
			$this->initView();
			die(json_encode(array('empty' => $empty,'tbody'=>$html,'dump'=>$_REQUEST,'statu'=>$statu, 'pages' => $this->view->get('pages'))));
		}else{
			if($Systempages){
				$ModulesDB = D('Modules');
			    $this->initView();
				$this->getModulesByID($this->view, $ModulesDB);
			    $html = $this->view -> fetch(TMPL_PATH.'Home/TemplateDefault/Supplier-header.html');
			    $html .= $ModulesDB->getListToString($Systempages['page_view_id'],$this->view,false,true);
			    $html .= $this->view -> fetch(TMPL_PATH.'Home/TemplateDefault/Supplier-footer.html');
				echo $html;
			}else{
				parent::display($temp);
			}
			
			
		} 
	}
	
}